package com.croofr.utils.string;

/**
 * Utility for String.
 * <p/>
 * User: bednar<br/>
 * Date: Dec 26, 2009<br/>
 * Time: 7:17:38 PM
 */
public final class StringUtils
{

    /**
     * Return true id string is null or empty ("")
     *
     * @param string for check
     * @return true if string is empty else false
     */
    public static boolean isEmpty(String string)
    {
        //noinspection RedundantIfStatement
        if (string == null || string.length() == 0)
        {
            return true;
        }

        return false;
    }

    /**
     * Return true if string isnt empty
     *
     * @param string for check
     * @return true if string isnt empty else false
     */
    public static boolean isNotEmpty(String string)
    {
        return !isEmpty(string);
    }

    /**
     * Return true if all bytes of string is digit character.
     * If string is empty than return false.
     *
     * @param string for check
     * @return true if all bytes of string are digit else false
     */
    public static boolean isDigit(String string)
    {
        if (isEmpty(string))
        {
            return false;
        }

        for (Byte b : string.getBytes())
        {

            if (!Character.isDigit(b))
            {
                return false;
            }
        }

        return true;
    }

    /**
     * Return true id string contains byte which isnt digit.
     * If string is empty than return true.
     *
     * @param string for check
     * @return true if string contains any no digit byte
     */
    public static boolean isNotDigit(String string)
    {
        return !isDigit(string);
    }
}
